package club.banyuan;

import java.util.Arrays;

public class Window {

  public static int[] maxSlidingWindow(int[] nums, int k) {
    var queue = new MyQueue<Integer>();
    // 返回的数组
    int[] out = new int[nums.length + 1 - k];
    // out里面的下标 j
    int j = 0;
    int i = 0;

    // 初始化最开始的窗口
    for (; i < k; i++) {
      queue.offer(nums[i]);
    }

    out[j] = queue.getMax();

    // 遍历剩下的元素
    for (; i < nums.length; i++) {
      queue.poll();
      queue.offer(nums[i]);
      out[++j] = queue.getMax();
    }

    return out;
  }

  public static void main(String[] args) {
    int[] nums = {1, 3, -1, -3, 5, 3, 6, 7};
    var out = maxSlidingWindow(nums, 3);
    System.out.println(Arrays.toString(out));
  }
}
